package csu.rjxyg.factory.core;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;



//规定工厂获取实体类方法
public class BeanFactory extends BaseFactory{

	private final static String FACTORY_BEAN = "BeanFactoryName";
	
	
	protected BeanFactory(){
		
	}
	
	public static BeanFactory getBeanFactory(){
		try{
			DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
	        DocumentBuilder builder = dFactory.newDocumentBuilder();
	        Document doc;
	        File file = new File(BaseFactory.FILE_NAME);
	        doc = builder.parse(file);
	          
	        //获取包含类名的文本节点
	        String cName;
	        NodeList nl = doc.getElementsByTagName(FACTORY_BEAN);
	        Node temp = nl.item(0).getFirstChild();
	        cName = temp.getNodeValue();
	        return   (BeanFactory) Class.forName(cName).newInstance();
		        
		}catch(Exception e){
			e.printStackTrace();
		}
			return null;
	}
	
	public Object getBean(String beanName){
		
		
		 return null;
	}
	
}